package com.fxpc.hddc.fxpicture.jpa.dao.primary;


import com.fxpc.hddc.fxpicture.dto.primary.entity.FxPictureEntity;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;


/**
 * @author zyb
 * @date 2020-11-30
 */
@Repository
public interface FxPictureBaseDao extends JpaRepository<FxPictureEntity, String> {

    @Query(nativeQuery = true, value = "select * from fx_picture where  type='地震灾害房屋直接经济损失评估图' and attach_id is not null")
    List<FxPictureEntity> findPjAllTime();

    @Query(nativeQuery = true, value = "select * from fx_picture where SUBSTRING(create_time,1,10)= " +
            ":nowDay AND type='地震灾害房屋直接经济损失评估图' and attach_id is not null")
    List<FxPictureEntity> findPjOneDayDataByCreateTime(@Param(value = "nowDay") LocalDate nowDay);

    @Query(nativeQuery = true, value = "select * from fx_picture where type='地震灾害房屋破坏导致的死亡人口评估图' and attach_id is not null")
    List<FxPictureEntity> findPrAllTime();

    @Query(nativeQuery = true, value = "select * from fx_picture where SUBSTRING(create_time,1,10)= " +
            ":nowDay AND type='地震灾害房屋破坏导致的死亡人口评估图' and attach_id is not null")
    List<FxPictureEntity> findPrOneDayDataByCreateTime(@Param(value = "nowDay") LocalDate nowDay);

    Long count(Specification<FxPictureEntity> specification);

}
